package hibernate;

import java.util.ArrayList;

import org.hibernate.Session;

import metier.Statut;
import dao.DAOStatut;

public class DAOStatutHBM extends DAOHibernate implements DAOStatut {

	@SuppressWarnings("unchecked")
	@Override
	public ArrayList<Statut> loadAll() throws Exception {
		ArrayList<Statut>	tab = null;
		Session session = connect();
		
		tab = (ArrayList<Statut>) session.createQuery("FROM Statut").list();
		
		close(session);
		return tab;
	}

	@Override
	public Statut get(int id) throws Exception {
		Statut s = null;
		Session	session = connect();
		
		s = (Statut) session.get(Statut.class, id);
		
		close(session);
		return s;
	}

	@Override
	public void save(Statut statut) throws Exception {
			Session	session = connect();
		
		session.save(statut);
		
		close(session);		

	}

	@Override
	public void delete(Statut statut) throws Exception {
		Session	session = connect();
		
		session.delete(statut);
		statut.setIdStatut(-1);
		
		close(session);

	}

	@Override
	public void update(Statut statut) throws Exception {
		Session	session = connect();
		
		session.update(statut);
		
		close(session);

	}

}
